package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 虎哥
 */
@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {

    @Override
    public List<SpecParamDTO> querySpecParamsByCondition(Long categoryId, Long groupId, Boolean searching) {
        //判断条件是否为空
        if (categoryId == null && groupId == null) {
            //条件不能都为空
            throw new LyException(400, "条件不能都为空");
        }
        //按条件查询
        List<SpecParam> specParamList = query().eq(categoryId != null, "category_id", categoryId)
                .eq(groupId != null, "group_id", groupId)
                .eq(searching != null, "searching", searching)
                .list();
        //转换返回
        return SpecParamDTO.convertEntityList(specParamList);
    }
}